@extends('admin.frame_layout')
<?php $top_selected = "系统设置";$page_menu = "管理员" ?>

@section('content')
    <div class="formbody">
        <div class="formtitle"><span>管理员编辑</span></div>
        <form action="{{route('admin.admins.save',['id'=>(empty($admin)?0:$admin->id)])}}" method="post" id="admin">
            {!! csrf_field() !!}
            <ul class="forminfo">

                <li>
                    <label class="lable">管理员名称</label>
                    <input id="username" name="username" type="text" class="dfinput"
                           value="{{$admin->username or ""}}"/>
                    <i for="username">名称最长不超过20个字符</i>
                </li>
                <li>
                    <label class="lable">管理员密码</label>
                    <input id="userpass" name="userpass" type="password" class="dfinput"
                           value="{{$admin->userpass or ""}}"/>
                    <i for="userpass">字母大小写 + 数字 + 特殊符号 最长30位字符</i>
                </li>
                <li>
                    <label class="lable">确认密码</label>
                    <input id="repwd" name="repwd" type="password" class="dfinput"
                           value="{{$admin->userpass or ""}}"/>
                    <i for="repwd"></i>
                </li>

                <li><label class="lable">&nbsp;</label>
                    <input type="submit" class="btn" value="确认保存"/>
                </li>
            </ul>
        </form>
    </div>
@endsection

@section('footer')
    <script type="text/javascript">
        $("#admin").validate({
            rules: {
                username: {
                    required: true,
                    minlength: 5,
                    maxlength: 30
                },
                userpass: {
                    required: true,
                    minlength: 10,
                    maxlength: 30
                },
                repwd: {
                    required: true,
                    equalTo: "#userpass"
                }
            }, errorPlacement: function (error, element) {
                $(element).closest("form").find("i[for='" + element.attr("id") + "']").html(error);
            },
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        if (data.code == 0) {
                            toastr["success"](data.msg);
                            setInterval(function () {
                                window.location = "{{route('admin.admins')}}";
                            }, 2000);
                        } else {
                            toastr["error"](data.msg);
                        }
                    }
                });
            }
        });
    </script>
@endsection
